package fx.mine.active.component;

import io.github.palexdev.materialfx.controls.MFXButton;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import lombok.extern.log4j.Log4j2;

@Log4j2
public class SideBar extends VBox {
    public SideBar() {
        setPrefWidth(250);
        setPadding(new Insets(60, 0, 10, 10));

        AnchorPane.setTopAnchor(this, 0.0);
        AnchorPane.setLeftAnchor(this, 0.0);
        AnchorPane.setBottomAnchor(this, 0.0);

        addLogo();
        addText();
        addScrollPane();


        getStyleClass().add("sidebar");
        getStylesheets().add(getClass().getResource("/css/sidebar.css").toExternalForm());
    }

    private void addScrollPane() {
        ObservableList<Node> children = getChildren();

        SideScrollPane scrollPane = new SideScrollPane();

        setVgrow(scrollPane, Priority.ALWAYS);
        setMargin(scrollPane, new Insets(15.0, 0, 10.0, 5.0));

        children.add(scrollPane);
    }

    private void addText() {
        ObservableList<Node> children = getChildren();
        var header = new Label("精选");
        setMargin(header, new Insets(40, 0, 0, 5));
        children.add(header);
        header.getStyleClass().add("textShow");
        header.applyCss();
    }

    private void addLogo() {
        ObservableList<Node> children = getChildren();
        ImageView logo = new ImageView(getClass().getResource("/icon/activeLogo.png").toExternalForm());
        logo.setFitHeight(55);
        logo.setFitWidth(135);
        MFXButton mfxButton = new MFXButton("", logo);
        setMargin(mfxButton,new Insets(0,0,0,40));
        children.add(mfxButton);
    }
}
